package CustomDialogs;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JComboBox;

import EstructurasDeDatos.Grafo;
import Main.Aplicacion;

public class DialogCantidadCaminosLongN extends JDialog {

	private static final long serialVersionUID = 7996670754930909843L;
	private final JPanel contentPanel = new JPanel();

	/**
	 * Create the dialog.
	 */
	public DialogCantidadCaminosLongN(Aplicacion padre,String titulo,final Grafo grafo) {
		super(padre, true);
		setBounds(100, 100, 493, 274);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		JLabel lblTitulo = new JLabel(titulo);
		lblTitulo.setBounds(22, 11, 402, 35);
		contentPanel.add(lblTitulo);
		
		final JComboBox<String> jComboBoxNodoOrig = new JComboBox<String>();
		jComboBoxNodoOrig.setBounds(48, 104, 128, 27);
		contentPanel.add(jComboBoxNodoOrig);
		
		final JComboBox<String> jComboBoxNodoDest = new JComboBox<String>();
		jComboBoxNodoDest.setBounds(254, 104, 128, 27);
		contentPanel.add(jComboBoxNodoDest);
		
		for(String node : grafo.getNombresNodos()){
			jComboBoxNodoOrig.addItem(node);
			jComboBoxNodoDest.addItem(node);
		}
		
		JLabel jLabelNodoOrig = new JLabel("Nodo origen:");
		jLabelNodoOrig.setBounds(48, 66, 128, 27);
		contentPanel.add(jLabelNodoOrig);
		
		JLabel jLabelNodoDest = new JLabel("Nodo destino:");
		jLabelNodoDest.setBounds(254, 66, 128, 27);
		contentPanel.add(jLabelNodoDest);
		
		JLabel lblLaCantidadDe = new JLabel("La cantidad de caminos de longitud");
		lblLaCantidadDe.setBounds(48, 160, 205, 27);
		contentPanel.add(lblLaCantidadDe);
		
		final JComboBox<String> jComboBoxLongitudCamino = new JComboBox<String>();
		jComboBoxLongitudCamino.setBounds(263, 163, 42, 20);
		for(int i=1;i<=10;i++){
			jComboBoxLongitudCamino.addItem(""+i);
		}
		contentPanel.add(jComboBoxLongitudCamino);
		
		JLabel lblEs = new JLabel("es");
		lblEs.setBounds(315, 166, 19, 14);
		contentPanel.add(lblEs);
		
		final JLabel jLabelCantidadCaminos = new JLabel("-");
		jLabelCantidadCaminos.setBounds(344, 160, 52, 27);
		contentPanel.add(jLabelCantidadCaminos);
		
		JButton btnVer = new JButton("(Ver)");
		btnVer.setBounds(396, 160, 67, 27);
		btnVer.addActionListener(new ActionListener() {		
			public void actionPerformed(ActionEvent e) {
				int cantidadCams=grafo.cantCaminosLongituN((String)jComboBoxNodoOrig.getSelectedItem(),(String)jComboBoxNodoDest.getSelectedItem(),Integer.parseInt((String)jComboBoxLongitudCamino.getSelectedItem()));
				jLabelCantidadCaminos.setText(""+cantidadCams);
			}
		});
		contentPanel.add(btnVer);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				okButton.addActionListener(new ActionListener() {		
					public void actionPerformed(ActionEvent e) {
						cerrarVentana();
					}
				});
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
		
		setLocation(padre.getLocationOnScreen().x+(padre.getWidth()-this.getWidth())/2,padre.getLocationOnScreen().y+(padre.getHeight()-this.getHeight())/2);
		setResizable(false);
		setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		setVisible(true);
	}
	
	private void cerrarVentana(){
		dispose();
	}
}
